﻿<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>一人一本 - 试过才知道</title>
    <link href="css/productlist.css" rel="stylesheet">
    <link href="css/inspiritas.css" rel="stylesheet">
    <link href="css/carousel.css" rel="stylesheet">
    <link href="css/bootstrap-tables.css" rel="stylesheet">
    <link href="css/prettify.css" rel="stylesheet">
    <link href="css/tablecloth.css" rel="stylesheet">
	<link href="css/bootstrap-datetimepicker.min.css" rel="stylesheet">
    <script src="js/jquery-1.7.1.min.js"></script>
    <script src="js/jquery.form.js"></script>
    <script src="js/jquery.json-2.4.js"></script>
    <script src="js/jquery.cookie.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/jquery.tablesorter.min.js"></script>
    <script src="js/jquery.tablecloth.js"></script>
    <script src="js/jquery.metadata.js"></script>
	<script src="js/bootstrap-datetimepicker.min.js"></script>
    <script>
        $(document).ready(
		function () {
		    typeListClick();

		<?php include "htm/ready.htm";?>

		    $.getJSON('index.php?act=customer.get_customer_inofrmation', function (data) {
		        $('#user_name').val(data.ret.Name);
		        $('#user_email').val(data.ret.Email);
		        $('#user_location').val(data.ret.Location);
		    }
			);
		}
		);

        $(document).on("click", ".btn-order-view", function () {
            var orderId = $(this).data('id');
            $('#orderid_show').text(orderId);
            $('#order_detail_table').empty();
            $.getJSON('index.php?act=order.get_order_detail&orderid=' + orderId, function (data) {
                for (var order_detail in data.ret) {
                    var html = '<tr><td><img src="' + data.ret[order_detail].IMAGE + '" class="img-rounded" width="100" ></td><td>' + data.ret[order_detail].ProductID + '</td><td>' + data.ret[order_detail].ProductName + '</td><td>' + data.ret[order_detail].Author + '</td><td>￥ ' + data.ret[order_detail].TotalPrice + '</td><td>' + data.ret[order_detail].Amount + '</td></tr>';
                    $('#order_detail_table').append(html);
                }
            });

            $(".modal-body #orderId").text("" + orderId);
            $('#orderDetails').modal('show');
        });
        function typeListClick() {
            $('#manage-list').children(':not(".divider,h3")').click(function () {
                $(this).addClass('active');
                $(this).siblings().removeClass('active');
            });
            $('#user_address').click(function () {
                $('#address_table').empty();
                $.getJSON('index.php?act=address.get_default_address', function (data) {
                    if (data.success) {
                        var address = data.ret.Address + " " + data.ret.Postal + " " + data.ret.Receiver + " " + data.ret.Phone;
                        $('#default_address').text(address);
                    }
                    else {
                        $('#default_address').text("");
                    }
                }
				);
                $.getJSON('index.php?act=address.get_all_address', function (data) {
                    for (var address in data.ret) {
                        var html = '<tr style="font-size:0.8em;">' + '<td>' + data.ret[address].Address + '</td>' + '<td>' + data.ret[address].Postal + '</td>' + '<td>' + data.ret[address].Receiver + '</td>' + '<td align="right">' + data.ret[address].Phone + '</td>' + '<td><a href="#" class="btn btn-success span8" onclick="return setDefaultAddress(' + data.ret[address].ID + ');">设为默认地址</a><a href="#" class="btn btn-danger span4" onclick="return deleteAddress(' + data.ret[address].ID + ');">删除</a></td>' + '</tr>';
                        $('#address_table').append(html);
                    }
                }
				);
                $("#personInfo").addClass("hidden");
                $("#addressInfo").removeClass("hidden");
                $("#orderInfo").addClass("hidden");
                $("#favouritesInfo").addClass("hidden");
            });


            $('#user_information').click(function () {
                $.getJSON('index.php?act=customer.get_customer_inofrmation', function (data) {
                    $('#user_name').val(data.ret.Name);
                    $('#user_email').val(data.ret.Email);
                    $('#user_location').val(data.ret.Location);
                }
				);
                $("#personInfo").removeClass("hidden");
                $("#addressInfo").addClass("hidden");
                $("#orderInfo").addClass("hidden");
                $("#favouritesInfo").addClass("hidden");
            });

            $('#user_favorite').click(function () {
                $('#all_favorites').empty();
                $.getJSON('index.php?act=favorite.get_all_favorite', function (data) {
                    var i = 0;
                    var html = "";

                    for (var favorite in data.ret) {
                        if (i > 0 && i % 4 == 0) {
                            html = html + '</div>';
                        }
                        if (i % 4 == 0) {
                            html = html + '<div class="row-fluid product-row">';
                        }
                        html = html +
							'<div class="span3 book-item">' +
							'<div class="hover-buttons hidden">' +
							'<button type="button" class="btn btn-mini btn-danger" onclick="return deleteFavorite(' + data.ret[favorite].ID + ');">' +
							'<em></em>' +
							'<span class="accessibilityText">删除</span>' +
							'</button>' +
							'</div>' +
							'<a id="fav-item-img" href="productDetail.php?product_id='+data.ret[favorite].ProductID+'">' +
							'<img src="' + data.ret[favorite].IMAGE + '" class="img-rounded" width="160">' +
							'</a>' +
							'<div class="book-info-list">' +
							'<a href="productDetail.php?product_id='+data.ret[favorite].ProductID+'" class="book-name-list">' + data.ret[favorite].Name + '</a>' +
							'<div id="authors">' +
							'<span class="carat juicy">›</span>' +
							'<a class="text-normal" href="javascript:void(0)">' + data.ret[favorite].Author + '</a>' +
							'</div>' +
							'</div>' +
							'</div>';
                        i++;
                    }
                    if (i > 0) {
                        html = html + '</div>';
                    }
                    $('#all_favorites').append(html);
                });

                $("#personInfo").addClass("hidden");
                $("#addressInfo").addClass("hidden");
                $("#orderInfo").addClass("hidden");
                $("#favouritesInfo").removeClass("hidden");
            });

            $('#user_order').click(function () {
                $('#order_table').empty();
                $.getJSON('index.php?act=order.get_all_order', function (data) {
                    for (var order in data.ret) {
                        var html = '<tr style="font-size:0.8em;">' + '<td>' + data.ret[order].ID + '</td>' + '<td>' + data.ret[order].OrderState + '</td>'
										+ '<td>' + data.ret[order].OrderTime + '</td>' + '<td>￥ ' + data.ret[order].TotalPrice + '</td>' + '<td><address>收件人：<span id="receiver">' +
										data.ret[order].Receiver + '<span><br>' + data.ret[order].Address + '<br>' + data.ret[order].Postal + '<br><abbr title="联系方式">Tel:</abbr>' +
										data.ret[order].Phone + '</address></td><td><a href="#orderDetails" class="btn btn-warning btn-order-view" data-id="' + data.ret[order].ID + '" data-toggle="modal">' +
										'查看订单</a><br><br><br>';
                        $('#order_table').append(html);
                    }
                });

                $("#personInfo").addClass("hidden");
                $("#addressInfo").addClass("hidden");
                $("#orderInfo").removeClass("hidden");
                $("#favouritesInfo").addClass("hidden");
            });
        }

    </script>
	<script>
	$(document).on("mouseenter", ".book-item", function () {
		$(this).find(".hover-buttons").removeClass("hidden");
		$(this).find("#fav-item-img").addClass("mantle");
	});
	$(document).on("mouseleave", ".book-item", function () {
		$(this).find(".hover-buttons").addClass("hidden");
		$(this).find("#fav-item-img").removeClass("mantle");
	});
</script>
</head>
<body>
    <div class="container">
        
<?php include "htm/head.htm";?>
        <div class="row">
            <div id="user_panel" class="span2  user-panel" style="left: 60px;">
                <ul id="manage-list" class="nav nav-list " style="postition: fixed">
                    <h3>
                        <li class="nav-header" style="font-weight: bold;">关于我</li></h3>
                    <li class="divider"></li>
                    <li id="" class="active"><a class="type-link" id="user_information" href="#">&nbsp;<span
                        style="float: right;">个人资料和密码</span></a></li>
                    <li class=""><a class="type-link" id="user_address" href="#">&nbsp;<span style="float: right;">我的收货地址</span></a></li>
                    <li id="" class=""><a class="type-link" id="user_order" href="#">&nbsp;<span style="float: right;">我的订单</span></a></li>
                    <li class=""><a class="type-link" id="user_favorite" href="#">&nbsp;<span style="float: right;">收藏夹</span></a></li>
                </ul>
            </div>
            <div id="addressInfo" class="span10 pull-right hidden">
                <div class="row-fluid">
                    <h1 class="span8 rhine">
                        设置 <small>收货地址</small></h1>
                </div>
                <div class="row-fluid">
                    <div class="delete-side ">
                        <h6 class="sidebar-title">
                            默认收货地址：</h6>
                        <div class="cnt" id="default_address">
                        </div>
                    </div>
                </div>
                </br></br>
                <div class="row-fluid">
                    <table cellspacing="1" id="addresses" cellpadding="3" class="table table-default table-bordered table-striped table-condensed ">
                        <thead>
                            <tr>
                                <th class>
                                    地址
                                </th>
                                <th class>
                                    邮编
                                </th>
                                <th class>
                                    收件人
                                </th>
                                <th class>
                                    联系方式
                                </th>
                                <th>
                                    <span></span>
                                </th>
                            </tr>
                        </thead>
                        <tbody id="address_table">
                        </tbody>
                    </table>
                </div>
                <div class="row-fluid">
                    <div class="delete-side ">
                        <form accept-charset="UTF-8" action="index.php?act=address.add_address" class="form-horizontal"
                        id="add_address" method="post" onsubmit="return addAddress();">
                        <fieldset>
                            <h6 class="sidebar-title">
                                添加新地址</h6>
                            <div class="cnt">
                                <div class="control-group  ">
                                    <label class="control-label" for="address">
                                        <abbr title="required">
                                            *</abbr>
                                        地址</label><div class="controls">
                                            <input class="span6" id="address" name="address" size="50" type="text" style="height: 30px;"></div>
                                </div>
                                <div class="control-group  ">
                                    <label class="control-label" for="postal">
                                        <abbr title="required">
                                            *</abbr>
                                        邮编</label><div class="controls">
                                            <input class="span5" id="postal" name="postal" size="50" type="text" style="height: 30px;"></div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="receiver">
                                        <abbr title="required">
                                            *</abbr>收件人</label><div class="controls">
                                                <input class="span5" id="receiver" name="receiver" size="50" type="text"></div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="tel">
                                        <abbr title="required">
                                            *</abbr>联系方式</label><div class="controls">
                                                <input class="span5" id="tel" name="phone" size="50" type="text"></div>
                                </div>
                                <div class="form-actions">
                                    <input class="btn btn-primary" data-disable-with="正在保存" name="commit" type="submit"
                                        value="添加地址">
                                </div>
                            </div>
                        </fieldset>
                        </form>
                    </div>
                </div>
            </div>
            <div id="personInfo" class="span10 pull-right ">
                <div class="row-fluid">
                    <h1 class="span8 rhine">
                        设置 <small>修改个人资料和密码</small></h1>
                </div>
                <div class="row-fluid">
                    <div class="span8">
                        <form accept-charset="UTF-8" action="index.php?act=customer.update_customer_information"
                        class="form-horizontal" id="edit_user" method="post" onsubmit="return updateUser();">
                        <fieldset>
                            <legend>个人资料设置</legend>
                            <div class="control-group  ">
                                <label class="control-label" for="user_name">
                                    名字</label><div class="controls">
                                        <input class="span7" id="user_name" name="user[name]" size="50" type="text" value=""
                                            style="height: 30px;"></div>
                            </div>
                            <div class="control-group ">
                                <label class=" control-label" for="user_email">
                                    <abbr title="required">
                                        *</abbr>
                                    Email</label><div class="controls">
                                        <input class="span7" disabled="disabled" id="user_email" name="user[email]" size="50"
                                            type="email" value=""></div>
                            </div>
                            <div class="control-group">
                                <label class="control-label" for="user_location">
                                    城市</label><div class="controls">
                                        <input class="span6" id="user_location" name="user[location]" size="50" type="text"><p
                                            class="help-block">
                                            请用中文填写所在城市, 如: 北京 海淀区</p>
                                    </div>
                            </div>
                            <div class="form-actions">
                                <input class="btn btn-primary" data-disable-with="正在保存" name="commit" type="submit"
                                    value="更新资料">
                            </div>
                        </fieldset>
                        </form>
                        <form accept-charset="UTF-8" action="index.php?act=customer.update_customer_password" class="form-horizontal"
                        id="edit_password" method="post" onsubmit="return updatePassword();">
                        <fieldset>
                            <legend>修改密码</legend>
                            <br>
                            <div class="control-group">
                                <label class="control-label" for="user_current_password">
                                    旧密码</label><div class="controls">
                                        <input class="password optional" id="user_current_password" name="user[current_password]"
                                            size="50" type="password"></div>
                            </div>
                            <div class="control-group">
                                <label class="control-label" for="user_password">
                                    密码</label><div class="controls">
                                        <input class="password optional" id="user_password" name="user[password]" size="50"
                                            type="password"></div>
                            </div>
                            <div class="control-group">
                                <label class="control-label" for="user_password_confirmation">
                                    确认密码</label><div class="controls">
                                        <input class="password optional" id="user_password_confirmation" name="user[password_confirmation]"
                                            size="50" type="password"></div>
                            </div>
                            <div class="form-actions">
                                <input class="btn btn-success" data-disable-with="正在保存" name="commit" type="submit"
                                    value="修改密码">
                            </div>
                        </fieldset>
                        </form>
                    </div>
                </div>
            </div>
            <div id="favouritesInfo" class="span10 pull-right hidden">
                <div class="row-fluid">
                    <h1 class="span8 rhine">
                        我的收藏夹</h1>
                </div>
                <div class="row-fluid product-row" id="all_favorites">
                </div>
                <div style="margin-top: 50px; margin-bottom: 100px;">
                </div>
            </div>
            <div id="orderInfo" class="span10 pull-right hidden" style="margin-right: 0;">
                <div class="row-fluid">
                    <h1 class="span8 rhine">
                        我的订单</h1>
                </div>
				<div class="row-fluid">
					<form accept-charset="UTF-8" action="index.php?act=order.get_order_by_date_range"
                        class="form-horizontal" id="get_order_by_date" method="post" onsubmit="return getOrderByDate();">
						<fieldset>
							  <span>起始时间:</span>
							  <span id="datetimepicker1" class="input-append date">
								<input data-format="yyyy-MM-dd" id="start_time_picker" name="starttime" type="text" style="height:30px;"></input>
								<span class="add-on">
								  <i data-time-icon="icon-time" data-date-icon="icon-calendar">
								  </i>
								</span>
							  </span>
							  <span>结束时间:</span>
							  <span id="datetimepicker2" class="input-append date">
								<input data-format="yyyy-MM-dd" id="end_time_picker" name="endtime" type="text" style="height:30px;"></input>
								<span class="add-on">
								  <i data-time-icon="icon-time" data-date-icon="icon-calendar">
								  </i>
								</span>
							  </span>
							  <input class="btn btn-primary" data-disable-with="正在查询" name="commit" type="submit"
                                    value="查询">
						</fieldset>
					</form>
				</div>
                <div class="">
                    <table id="order-overview" cellspacing="1" cellpadding="3" class=" table table-paper table-bordered table-condensed table-striped ">
                        <thead>
                            <tr>
                                <th>
                                    订单号
                                </th>
                                <th>
                                    状态
                                </th>
                                <th>
                                    时间
                                </th>
                                <th>
                                    总金额
                                </th>
                                <th>
                                    地址
                                </th>
                                <th>
                                </th>
                            </tr>
                        </thead>
                        <tbody id="order_table">
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
    
    <div id="orderDetails" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="login-label"
        aria-hidden="true" style="top: 40%; left: 25%; width: 90%">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                ×</button>
            <div id="login-label" class="juicy login-title">
                订单详细信息</div>
        </div>
        <div class="modal-body">
            <div class="hidden" id="orderId">
            </div>
            <div class="row-fluid">
                <h3 class="rhine">
                    订单</h3>
                <span id="orderid_show" class="smoke" style="float: left">0918203919203</span>
            </div>
            <table cellspacing="1" cellpadding="3" class=" table table-default table-bordered table-striped ">
                <thead>
                    <tr>
                        <th>
                            &nbsp;
                        </th>
                        <th>
                            商品编号
                        </th>
                        <th>
                            书名
                        </th>
                        <th>
                            作者
                        </th>
                        <th>
                            总价
                        </th>
                        <th>
                            数量
                        </th>
                    </tr>
                </thead>
                <tbody id="order_detail_table">
                </tbody>
            </table>
        </div>
    </div>
<?php include "htm/footer.htm";?>
    <script>
        function updateUser() {
            $("#edit_user").ajaxSubmit(function (message) {
                var obj = $.evalJSON(message);
                if (obj.success) {
                    alert("更新成功");
                }
                else {
                    alert("更新失败\n"+obj.msg);
                }
                location.reload();
            });

            return false;
        } 
    </script>
    <script>
        function updatePassword() {

            $("#edit_password").ajaxSubmit(function (message) {
                var obj = $.evalJSON(message);
                if (obj.success) {
                    alert("密码更新成功");
                }
                else {

                    alert(obj.msg)
                }
                location.reload();
            });

            return false;
        }
    </script>
    <script>
        function addAddress() {

            $("#add_address").ajaxSubmit(function (message) {
                var obj = $.evalJSON(message);
                if (obj.success) {
                    $('#user_address').click();
                }
                else {
                    alert("添加失败\n"+obj.msg);
                }
            });

            return false;
        }
    </script>
    <script>
        function setDefaultAddress(id) {
            $.ajax({
                url: 'index.php?act=address.set_default_address&addressid=' + id,
                type: 'GET',
                success: function (data) {
                    $('#user_address').click();
                }
            });
            return false;
        }
    </script>
    <script>
        function deleteAddress(id) {
            $.ajax({
                url: 'index.php?act=address.delete_address&addressid=' + id,
                type: 'GET',
                success: function (data) {
                    $('#user_address').click();
                }
            });
            return false;
        }
    </script>
	<script>
        function deleteFavorite(id) {
            $.ajax({
                url: 'index.php?act=favorite.delete_favorite&favoriteid=' + id,
                type: 'GET',
                success: function (data) {
                    $('#user_favorite').click();
                }
            });
            return false;
        }
    </script>
	<script>
		function getOrderByDate() {
			$('#get_order_by_date').ajaxSubmit(function (message) {
				$('#order_table').empty();
                var data = $.evalJSON(message);
                    for (var order in data.ret) {
                        var html = '<tr style="font-size:0.8em;">' + '<td>' + data.ret[order].ID + '</td>' + '<td>' + data.ret[order].OrderState + '</td>'
										+ '<td>' + data.ret[order].OrderTime + '</td>' + '<td>￥ ' + data.ret[order].TotalPrice + '</td>' + '<td><address>收件人：<span id="receiver">' +
										data.ret[order].Receiver + '<span><br>' + data.ret[order].Address + '<br>' + data.ret[order].Postal + '<br><abbr title="联系方式">Tel:</abbr>' +
										data.ret[order].Phone + '</address></td><td><a href="#orderDetails" class="btn btn-warning btn-order-view" data-id="' + data.ret[order].ID + '" data-toggle="modal">' +
										'查看订单</a><br><br><br>';
                        $('#order_table').append(html);
                    }
            });
			return false;
		}
	</script>
	<script type="text/javascript">
		$(function() {
			$('#datetimepicker1').datetimepicker({
				maskInput: true, 
				pickDate: true,  
				pickTime: false,  
				startDate: -Infinity,
				endDate: Infinity,  
				language: 'en'
			});
		});
	</script>
	<script type="text/javascript">
		$(function() {
			$('#datetimepicker2').datetimepicker({
				maskInput: true, 
				pickDate: true,  
				pickTime: false,  
				startDate: -Infinity,
				endDate: Infinity,  
				language: 'en'
			});
		});
	</script>
</body>
</html>
